package com.gilgamesh.mall.product.controller;

import com.gilgamesh.mall.product.service.ImageService;
import com.gilgamesh.mall.product.service.OutofstockService;
import com.gilgamesh.mall.product.service.ProductDetailService;
import com.gilgamesh.mall.product.service.ProductService;
import com.gilgamesh.mall.product.service.ShopService;
import com.gilgamesh.mall.product.service.StockService;
import com.gilgamesh.mall.sdk.bean.product.ProductEntity;
import com.gilgamesh.mall.sdk.client.product.ProductClient;
import com.gilgamesh.mall.sdk.dto.ResponseDTO;
import com.gilgamesh.mall.sdk.dto.product.ImageDTO;
import com.gilgamesh.mall.sdk.dto.product.ProductDTO;
import com.gilgamesh.mall.sdk.util.ResponseUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

import java.util.List;

/**
 * @author yanm
 * @date 2021/1/11 13:05
 **/
@RestController
@RequestMapping("api/pdt")
@CrossOrigin
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ProductController implements ProductClient {
    private final ProductService productService;

    private final ProductDetailService productDetailService;

    private final ImageService imageService;

    private final ShopService shopService;

    private final StockService stockService;

    private final OutofstockService outofstockService;



    @PostMapping("addProduct")
    public ResponseDTO<Integer> createProduct(@RequestParam(value = "description",required = false) String description,
                                              @RequestParam(value = "classfic3Id",required = false) Long classfic3Id,
                                              @RequestParam(value = "classfic2Id",required = false) Long classfic2Id,
                                              @RequestParam(value = "classficId",required = false) Long classficId,
                                              @RequestParam(value = "shopCode",required = false) String shopCode,
                                              @RequestParam(value = "showPictureUrl",required = false) String showPictureUrl){
        ProductEntity entity = new ProductEntity();
        entity.setCreateTime(new Date());
        entity.setClassfic2Id(classfic2Id);
        entity.setClassfic3Id(classfic3Id);
        entity.setDescription(description);
        entity.setClassficId(classficId);
        entity.setShopCode(shopCode);
        entity.setShowPictureUrl(showPictureUrl);
        System.out.println("addProduct接口入参 = "+entity.toString());
        return productService.createProduct(entity);
    }

    @PostMapping("listProduct")
    public ResponseDTO<List<ProductDTO>> listProduct() {
        return productService.listProduct(null);
    }

    @GetMapping("getProduct/{id}")
    public ResponseDTO<ProductDTO> getById(@PathVariable(value = "id") Long id) {
        return productService.getProductById(id);
    }

    @PostMapping("getP")
    public ResponseDTO<String> getProductCode() {

        ResponseDTO<String> response = ResponseUtil.getResponse(productService.getProductCode());
        return response;
    }

    @PostMapping("getS")
    public ResponseDTO<String> getSkuCode() {
        ResponseDTO<String> response = ResponseUtil.getResponse(productService.getSkuCode());
        return response;
    }



    @PostMapping("deleteById")
    public ResponseDTO<Integer> deleteById(@RequestParam(value = "id") Long id) {
        /**
         *TODO
         **/
        System.out.println(id);
        return ResponseUtil.getResponse(new Integer(1));
    }

    @PostMapping("updateById")
    public ResponseDTO<Integer> updateById(@RequestBody ProductEntity productEntity){
        return ResponseUtil.getResponse(new Integer(1));
    }

    @PostMapping("createProduct")
    public ResponseDTO<Integer> createProduct(ProductEntity productEntity){
        return ResponseUtil.getResponse(new Integer(1));
    }

    @PostMapping("createImageName")
    public ResponseDTO<ImageDTO> getImageName(){
        return productService.getImageName();
    }
}
